﻿// FileExplorerDialog.cpp: 实现文件
//

#include "stdafx.h"
#include "zChecker.h"
#include "FileExplorerDialog.h"
#include "afxdialogex.h"


// CFileExplorerDialog 对话框

IMPLEMENT_DYNAMIC(CFileExplorerDialog, CDialogEx)

CFileExplorerDialog::CFileExplorerDialog(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG_FILE_EXPLORER, pParent)
{

}

CFileExplorerDialog::~CFileExplorerDialog()
{
}

void CFileExplorerDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_MFCSHELLTREE1, m_wndShellTree);
	DDX_Control(pDX, IDC_MFCSHELLLIST1, m_wndShellList);
}


BEGIN_MESSAGE_MAP(CFileExplorerDialog, CDialogEx)
	ON_BN_CLICKED(IDOK, &CFileExplorerDialog::OnBnClickedOk)
END_MESSAGE_MAP()


// CFileExplorerDialog 消息处理程序


BOOL CFileExplorerDialog::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化
	m_wndShellTree.Expand(m_wndShellTree.GetRootItem(), TVE_EXPAND);
	m_wndShellTree.SetRelatedList(&m_wndShellList);
	m_wndShellList.EnableShellContextMenu(FALSE);

	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}


void CFileExplorerDialog::OnBnClickedOk()
{
	// TODO: 在此添加控件通知处理程序代码
	CString strPath;
	HTREEITEM hItem = m_wndShellTree.GetSelectedItem();
	if (!hItem)
	{
		return;
	}
	BOOL ret = FALSE;
	ret = m_wndShellTree.GetItemPath(strPath, hItem);
	if (!ret)
	{
		return;
	}
	m_wndShellTree.GetItemPath(m_strPath, hItem);

	//////////////////////////////////////////////////////////////////////////
	m_names.Cleanup();
	POSITION pos = m_wndShellList.GetFirstSelectedItemPosition();
	while(pos != NULL)
	{
		int nItem = m_wndShellList.GetNextSelectedItem(pos);
		CString strName = m_wndShellList.GetItemText(nItem, 0);
		m_names.Add(strName);
	}

	CDialogEx::OnOK();
}
